<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    10 个冷门但又非常实用的 Docker 使用技巧.md |  
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

</head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-docker/10 个冷门但又非常实用的 Docker 使用技巧"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  10 个冷门但又非常实用的 Docker 使用技巧.md
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/11/11/docker/10%20%E4%B8%AA%E5%86%B7%E9%97%A8%E4%BD%86%E5%8F%88%E9%9D%9E%E5%B8%B8%E5%AE%9E%E7%94%A8%E7%9A%84%20Docker%20%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7/" class="article-date">
  <time datetime="2020-11-10T16:00:00.000Z" itemprop="datePublished">2020-11-11</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/docker/">docker</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.1k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">5 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="10-个冷门但又非常实用的-Docker-使用技巧"><a href="#10-个冷门但又非常实用的-Docker-使用技巧" class="headerlink" title="10 个冷门但又非常实用的 Docker 使用技巧"></a>10 个冷门但又非常实用的 Docker 使用技巧</h1><p><img src="http://iubest.gitee.io/pic/640-1601016782724.webp" alt="img"></p>
<p>在平时的工作中，docker 接触得很多，除了经常使用的 <code>docker run</code> ，<code>docker stop</code> 等命令，<code>docker</code> 还有很多十分有用但是却不经常使用的命令，下面就来总结一下：</p>
<h2 id="1-docker-top"><a href="#1-docker-top" class="headerlink" title="1. docker top"></a>1. docker top</h2><p>这个命令是用来查看一个容器里面的进程信息的，比如你想查看一个 <code>nginx</code> 容器里面有几个 <code>nginx</code> 进程的时候，就可以这么做：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ docker top 3b307a09d20d</span><br><span class="line">UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD</span><br><span class="line">root                805                 787                 0                   Jul13               ?                   00:00:00            nginx: master process nginx -g daemon off;</span><br><span class="line">systemd+            941                 805                 0                   Jul13               ?                   00:03:18            nginx: worker process</span><br></pre></td></tr></table></figure>

<h2 id="2-docker-load-amp-amp-docker-save"><a href="#2-docker-load-amp-amp-docker-save" class="headerlink" title="2. docker load &amp;&amp; docker save"></a>2. docker load &amp;&amp; docker save</h2><p>我一般使用这两个命令去下载打包 <code>Kubernetes</code> 的镜像，因为你知道的国内的网速并不像国外那么快。</p>
<p><code>docker save</code> 可以把一个镜像保存到 <code>tar</code> 文件中，你可以这么做：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ docker save registry:2.7.1 &gt;registry-2.7.1.tar</span><br></pre></td></tr></table></figure>

<p>同时 <code>docker load</code> 可以把镜像从 <code>tar</code> 文件导入到 <code>docker</code> 中</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ docker load &lt; registry-2.7.1.tar</span><br></pre></td></tr></table></figure>

<h2 id="3-docker-search"><a href="#3-docker-search" class="headerlink" title="3. docker search"></a>3. docker search</h2><p>这个命令可以帮助你在命令行中方便的搜索 <code>DockerHub</code> 中的镜像，比如:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ docker search nginx</span><br><span class="line">NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED</span><br><span class="line">nginx                              Official build of Nginx.                        13519               [OK]</span><br><span class="line">jwilder&#x2F;nginx-proxy                Automated Nginx reverse proxy for docker con…   1846                                    [OK]</span><br><span class="line">richarvey&#x2F;nginx-php-fpm            Container running Nginx + PHP-FPM capable of…   780                                     [OK]</span><br><span class="line">linuxserver&#x2F;nginx                  An Nginx container, brought to you by LinuxS…   123</span><br><span class="line">bitnami&#x2F;nginx                      Bitnami nginx Docker Image                      87                                      [OK]</span><br><span class="line">tiangolo&#x2F;nginx-rtmp                Docker image with Nginx using the nginx-rtmp…   85                                      [OK]</span><br><span class="line">jc21&#x2F;nginx-proxy-manager           Docker container for managing Nginx proxy ho…   73</span><br><span class="line">alfg&#x2F;nginx-rtmp                    NGINX, nginx-rtmp-module and FFmpeg from sou…   71                                      [OK]</span><br><span class="line">nginxdemos&#x2F;hello                   NGINX webserver that serves a simple page co…   57                                      [OK]</span><br><span class="line">jlesage&#x2F;nginx-proxy-manager        Docker container for Nginx Proxy Manager        53                                      [OK]</span><br><span class="line">nginx&#x2F;nginx-ingress                NGINX Ingress Controller for Kubernetes         37</span><br><span class="line">......</span><br></pre></td></tr></table></figure>

<p>当然这个功能在国内可能不会特别好用，因为……</p>
<h2 id="4-docker-events"><a href="#4-docker-events" class="headerlink" title="4. docker events"></a>4. docker events</h2><p>这个命令可以帮助你实时获取 <code>docker</code> 的各种事件信息，比如创建了一个容器什么的。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ docker events</span><br><span class="line">2020-07-28T21:28:46.000403018+08:00 image load sha256:432bf69f0427b52cad10897342eaf23521b7d973566354118e9a59c4d31b5fae (name&#x3D;sha256:432bf69f0427b52cad10897342eaf23521b7d973566354118e9a59c4d31b5fae)</span><br></pre></td></tr></table></figure>

<h2 id="5-docker-update"><a href="#5-docker-update" class="headerlink" title="5. docker update"></a>5. docker update</h2><p>当你 <code>docker run</code> 了之后却发现里面有一些参数并不是你想要的状态比如你设置的 <code>nginx</code>容器 <code>cpu</code> 或者内存太小，这个时候你就可以使用 <code>docker update</code> 去修改这些参数。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ docker update nginx --cpus 2</span><br></pre></td></tr></table></figure>

<h2 id="6-docker-history"><a href="#6-docker-history" class="headerlink" title="6. docker history"></a>6. docker history</h2><p>当你修改了一个镜像，但是忘记了每一层的修改命令，或者你想查看一个镜像是怎么构建的时候就可以使用这个命令，比如：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ docker history  traefik:v2.1.6</span><br><span class="line">IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT</span><br><span class="line">5212a87ddaba        5 months ago        &#x2F;bin&#x2F;sh -c #(nop)  LABEL org.opencontainers.…   0B</span><br><span class="line">&lt;missing&gt;           5 months ago        &#x2F;bin&#x2F;sh -c #(nop)  CMD [&quot;traefik&quot;]              0B</span><br><span class="line">&lt;missing&gt;           5 months ago        &#x2F;bin&#x2F;sh -c #(nop)  ENTRYPOINT [&quot;&#x2F;entrypoint.…   0B</span><br><span class="line">&lt;missing&gt;           5 months ago        &#x2F;bin&#x2F;sh -c #(nop)  EXPOSE 80                    0B</span><br><span class="line">&lt;missing&gt;           5 months ago        &#x2F;bin&#x2F;sh -c #(nop) COPY file:59a219a1fb7a9dc8…   419B</span><br><span class="line">&lt;missing&gt;           5 months ago        &#x2F;bin&#x2F;sh -c set -ex;  apkArch&#x3D;&quot;$(apk --print-…   52.9MB</span><br><span class="line">&lt;missing&gt;           5 months ago        &#x2F;bin&#x2F;sh -c apk --no-cache add ca-certificate…   1.85MB</span><br><span class="line">&lt;missing&gt;           6 months ago        &#x2F;bin&#x2F;sh -c #(nop)  CMD [&quot;&#x2F;bin&#x2F;sh&quot;]              0B</span><br><span class="line">&lt;missing&gt;           6 months ago        &#x2F;bin&#x2F;sh -c #(nop) ADD file:a1906f14a4e217a49…   4.81MB</span><br></pre></td></tr></table></figure>

<h2 id="7-docker-wait"><a href="#7-docker-wait" class="headerlink" title="7. docker wait"></a>7. docker wait</h2><p>这个命令可以查看容器的退出状态，比如：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ docker wait 7f7f0522a7d0</span><br><span class="line">0</span><br></pre></td></tr></table></figure>

<p>这样你就可以知道这个容器是正常退出的还是异常退出的了。</p>
<h2 id="8-docker-pause-amp-amp-docker-unpause"><a href="#8-docker-pause-amp-amp-docker-unpause" class="headerlink" title="8. docker pause &amp;&amp; docker unpause"></a>8. docker pause &amp;&amp; docker unpause</h2><p>当你运行了一个容器但是想要暂停它运行的时候，你就可以使用这个命令。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ docker pause 7f7f0522a7d0</span><br></pre></td></tr></table></figure>

<h2 id="9-docker-diff"><a href="#9-docker-diff" class="headerlink" title="9. docker diff"></a>9. docker diff</h2><p>当你运行了一个容器，但是你不知道容器里修改了哪一些文件的时候可以使用这个命令，比如：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ docker diff 38c59255bf6e</span><br><span class="line">C &#x2F;etc</span><br><span class="line">A &#x2F;etc&#x2F;localtime</span><br><span class="line">C &#x2F;var</span><br><span class="line">C &#x2F;var&#x2F;lib</span><br><span class="line">A &#x2F;var&#x2F;lib&#x2F;registry</span><br></pre></td></tr></table></figure>

<h2 id="10-docker-stats"><a href="#10-docker-stats" class="headerlink" title="10. docker stats"></a>10. docker stats</h2><p>这个是 <code>docker</code> 内置的监控命令，当你想要查看当前主机下所有容器占用内存和 <code>cpu</code> 的情况的时候就可以使用这个命令。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ docker stats</span><br><span class="line"></span><br><span class="line">CONTAINER ID        NAME                           CPU %               MEM USAGE &#x2F; LIMIT     MEM %               NET I&#x2F;O             BLOCK I&#x2F;O           PIDS</span><br><span class="line">1c5ade04e7f9        redis                          0.08%               17.53MiB &#x2F; 47.01GiB   0.04%               10.9GB &#x2F; 37GB       0B &#x2F; 0B             4</span><br><span class="line">afe6d4ebe409        kafka-exporter                 0.09%               16.91MiB &#x2F; 47.01GiB   0.04%               1.97GB &#x2F; 1.53GB     752MB &#x2F; 0B          23</span><br><span class="line">f0c7c01a9c34        kafka-docker_zookeeper         0.01%               308.8MiB &#x2F; 47.01GiB   0.64%               20.2MB &#x2F; 12.2MB     971MB &#x2F; 3.29MB      28</span><br><span class="line">da8c5008955f        kafka-docker_kafka-manager     0.08%               393.2MiB &#x2F; 47.01GiB   0.82%               1.56MB &#x2F; 2.61MB     1.14GB &#x2F; 0B         60</span><br><span class="line">c8d51c583c49        kafka-docker_kafka             1.63%               1.256GiB &#x2F; 47.01GiB   2.67%               30.4GB &#x2F; 48.9GB     22.3GB &#x2F; 5.77GB     85</span><br><span class="line">......</span><br></pre></td></tr></table></figure> 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明： </strong>
          
          本博客所有文章除特别声明外，著作权归作者所有。转载请注明出处！
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2020/11/11/docker/10%20%E4%B8%AA%E5%86%B7%E9%97%A8%E4%BD%86%E5%8F%88%E9%9D%9E%E5%B8%B8%E5%AE%9E%E7%94%A8%E7%9A%84%20Docker%20%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/docker/" rel="tag">docker</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2020/11/11/django/Django%20admin%E5%90%8E%E5%8F%B0%E7%AE%A1%E7%90%86%E4%B8%BB%E9%A2%98%E7%BE%8E%E5%8C%96/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            Django admin后台管理主题美化.md
          
        </div>
      </a>
    
    
      <a href="/2020/11/11/docker/Docker%20%E5%AE%B9%E5%99%A8%E9%97%B4%E7%9A%84%E5%85%8D%E5%AF%86%E7%99%BB%E9%99%86/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">Docker 容器间的免密登陆.md</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "",
    app_key: "",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2020
        <i class="ri-heart-fill heart_icon"></i> TzWind
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="Hexo"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" target="_blank" rel="noopener" href="http://www.baidu.com">百度</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2019/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


    
  </div>
</body>

</html>